package Lee_code;

import java.util.LinkedList;
import java.util.List;

public class Lee_797 {
    List<List<Integer>> res = new LinkedList<>();
    int len;
    public List<List<Integer>> allPathsSourceTarget(int[][] graph)
    {
        //共有len-1个点, 就是从0到len-1
        len = graph.length;
        List<Integer> list = new LinkedList<>();
        list.add(0);
        dfs(0, list, graph);
        return res;

    }

    private void dfs(int cur, List<Integer> list, int[][] graph)
    {
        if(cur == len-1) {
            res.add(new LinkedList<>(list));
            return;
        }
        int path = graph[cur].length;
        for(int next: graph[cur])
        {
            list.add(next);
            dfs(next, list, graph);
            list.remove(list.size()-1);
        }


    }
}
